home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / Logger.lha / logger1.0 / Logger < prev   
Encoding:
Text File  |  1995-04-19  |  4.0 KB  |  123 lines

  1. /************************************************** $VER: Logger v1.0 (19/04/95)
  2. * Andy's newest Arexx project.                    *
  3. * This latest project reads from a configuration  *
  4. * file which lists all your log files, and uses a *
  5. * 'Tail' command to trim them to the specified    *
  6. * length. It could possibly very easily be done   *
  7. * in AmigaDOS, but since Arexx is my flavour of   *
  8. * the month....here goes                          *
  9. * There is an alternative version called CLogger  *
  10. * that uses Arexx to do the trimming, rather than *
  11. * the external Tail command.                      *
  12. * This version is quicker. That version is all my *
  13. * own work, and is self contained.                *
  14. * Both require the awesome RexxReqTools by        *
  15. * Rafael D'Halleweyn.                             *
  16. **************************************************/
  17.  
  18.  
  19. /* variables you may change                      */
  20. configfile = 's:logger.config'
  21. lf         = '0a'x
  22.  
  23.  
  24.  
  25.  
  26. /* check for rexxreqtools                        */
  27. if exists('LIBS:rexxreqtools.library') then do
  28.     call addlib('rexxreqtools.library',0,-30)
  29. end
  30.  
  31. parse arg arguments
  32. if compress(arguments) ~= '' then do
  33.     if find(Upper(arguments),'LOGRESET') > 0 then signal logreset
  34.     if find(Upper(arguments),'CONFIG') > 0 then conf = 1
  35.     if find(Upper(arguments),'FORCE') > 0 then force = 1
  36.     if conf ~= 1&force ~= 1 then signal usage
  37. end
  38.  
  39. /* first get the config file                     */
  40.  
  41. if ~exists(configfile)|conf = 1 then do
  42.         call rtezrequest('    Are you sure you would'lf'like to create a new config file?','_Yes |_No','Logger v1.0','rt_reqpos = reqpos_centerscr')
  43.         frt = rtresult
  44.         if frt = 0&conf = 1 then do
  45.             call rtezrequest('Do you wish to use the old config?','_Yes|_No','Logger v1.0','rt_reqpos=reqpos_centerscr')
  46.             srt = rtresult
  47.             if srt = 0 then Exit
  48.             if srt = 1 then signal main
  49.         end
  50.         if frt = 0&conf ~= 1 then Exit
  51.     call loggerconfig
  52. end
  53.  
  54.  
  55.  
  56.  
  57. main:
  58. /* read the config file and 'tail' each log      */
  59.  
  60. call open(InpFile,configfile,R)
  61.  
  62. do forever
  63.     line = readln(InpFile)
  64.     if EOF(InpFile) then break
  65.     if left(line,1) ~= "#" then do
  66.         if compress(line) ~= ""  then do
  67.             taillen = subword(line,2,1)
  68.             tailfile = subword(line,1,1)
  69.             if exists(tailfile) then do
  70.                 if force ~= 1 then do
  71.                     call rtezrequest(' Are you sure you wish to trim'lf tailfile lf' to last 'taillen,'_Yes | _No','Logger v1.0','rt_reqpos=reqpos_centerscr')
  72.                     frt = rtresult
  73.                     end
  74.                 if frt ~= 0|force = 1 then do
  75.                     address command 'delete >NIL: 'tailfile'.bak'
  76.                     address command 'rename from 'tailfile' to 'tailfile'.bak'
  77.                     address command 'tail -'taillen ' >'tailfile' 'tailfile'.bak'
  78.                 end
  79.             end
  80.         end
  81.     end
  82. end
  83.  
  84. call close(InpFile)
  85. exit
  86. usage:
  87.  
  88. say 'Logger [CONFIG] [FORCE] [LOGRESET]'
  89. exit
  90.  
  91.  
  92. loggerconfig:
  93. call open(Outfile,configfile,W)
  94. call writeln(OutFile,'# Config file created by Logger v1.0')
  95. do forever
  96.     logstring = rtfilerequest('work:',,'Logger.config',,'rtfi_matchpat=#?.log rtfi_flags=freqf_patgad rt_reqpos=reqpos_centerscr')
  97.     frt = rtresult
  98.     if frt = 0 then break
  99.     logno = rtgetlong('200','trim 'logstring' to how many?','Logger.config',,'rtgl_min=0 rt_reqpos=reqpos_centerscr')
  100.     frt = rtresult
  101.     if frt = 0 then break
  102.     call writeln(Outfile,logstring' 'logno)
  103. end
  104. call close(outfile)
  105. return
  106.  
  107.  
  108. /*logresetter*/
  109. logreset:
  110. rtezrequest('Are you sure you wish to reset your logs?'lf'This will replace all the logfiles in your config'lf'with their backups!','_Yes|_No','Logger v1.0','rt_reqpos=reqpos_centerscr rtez_defaultresponse=0')
  111. open(inpfile,configfile,R)
  112. do forever
  113.     line = readln(inpfile)
  114.     if EOF(InpFile) then break
  115.     rfile = subword(line,1,1)
  116.     if exists(rfile'.bak') then do
  117.         address command 'delete >NIL: 'rfile
  118.         address command 'rename 'rfile'.bak' rfile
  119.     end
  120. end
  121. exit
  122.  
  123.